<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>

<body>
    <div id="div">
        姓<input type="text" v-model="firstname">+
        名<input type="text" v-model="lastname">=
        {{fullname}}
        <br>
        <button @click="changename">改名卡</button>
    </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
    const app = new Vue({
        el: '#div',
        data: {
            firstname: "",
            lastname: "",

        },
        methods: {
            changename() {
                this.fullname = "李白"
            }
        },
        // 在computed中定义方法，返回计算属性
        computed: {
            fullname: {
                //fullname会将get方法返回值作为fullname的值
                get() {
                    return this.firstname + this.lastname
                },
                //改变fullname值时执行set方法
                set(value) {
                    this.firstname = value.slice(0, 1)
                    this.lastname = vavle.slice(1)
                }
            }
        }

    })
</script>

</html>